<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>练习5：找重复元素.html</title>
</head>
<body>

    <div>
        <button onclick="chongfu()">点击获取到相同的数组元素，控制台查看</button>
    </div>

    <script>
        function chongfu(){
            var arr=['apple',3,'banana',3,'pear',2,3,'apple'];
            var nary=arr.sort();//加上这个，不加不生效
            for(var i=0;i<arr.length;i++){
                if(nary[i]==nary[i+1]){
                    console.log("["+nary[i]+"]");
                }

            }
        }
    </script>
</body>
</html>